<?php
/**
 * User: zoudingyong <sheyingtg@qq.com>
 * Date: 2018-9-6 10:08
 */

namespace classes;

use think\Queue;
use think\Db;
class WxPush
{

    /**
     * 公众号支付成功通知
     * @param $member
     * @param $order
     * @return bool
     */
    static public function buy($member, $order)
    {
        if (empty($member)) return false;

        $goods_name = Db::name('jixie_order_goods')
            ->where('order_id', $order['order_id'])
            ->value('goods_name');

        $data = [
            'touser' => $member['open_id'],
            'template_id' => 'oJcprQKpze2ZYFhdWgkb0HciWNXJLg1x6nYuAQhlk2s',
            'url' => '',
            'topcolor' => "#FF0000",
            'data' => array(
                'keyword1' => array('value' => $goods_name, "color" => "#173177"),
                'keyword2' => array('value' => $order['order_no'], "color" => "#173177"),
                'keyword3' => array('value' => $order['total_price'], "color" => "#173177"),
                'keyword4' => array('value' => $order['create_at'], "color" => "#173177"),
                'keyword5' => array('value' => $order['pay_time'], "color" => "#173177"),
                'keyword6' => array('value' => $order['pay_price'], "color" => "#173177"),
            )
        ];
        Queue::push('app\job\push@wxPush', $data);
    }

    /**
     * 小程序支付成功通知
     * @param $member
     * @param $order
     * @return bool
     */
    static public function smallBuy($member, $order)
    {
        if (empty($member)) return false;

        $goods_name = Db::name('jixie_order_goods')
            ->where('order_id', $order['order_id'])
            ->value('goods_name');

        $data =        [
            'touser' => 'oNQYF0an8aX-s_v0llT0SapPfrIE',
            'template_id' => 't3P6xOunHM6LM_EMLc-R0geRJ1NFQOopVhi06PiAbXE',
            'form_id' => 'wx130859406128303dfc783bc03128125746', //表单提交场景下，为 submit 事件带上的 formId；支付场景下，为本次支付的 prepay_id
            //https://blog.csdn.net/zhy13087344578/article/details/78881063
            //  https://blog.csdn.net/G_onion/article/details/79734607
            'page' => 'pages/index/index',
            'color ' => "#FF0000",
            'data' => array(
                'keyword1' => array('value' => $goods_name, "color" => "#173177"),
                'keyword2' => array('value' => $order['order_no'], "color" => "#173177"),
                'keyword3' => array('value' => $order['total_price'], "color" => "#173177"),
                'keyword4' => array('value' => $order['create_at'], "color" => "#173177"),
                'keyword5' => array('value' => $order['pay_time'], "color" => "#173177"),
                'keyword6' => array('value' => $order['pay_price'], "color" => "#173177"),
            )
        ];
        Queue::push('app\job\push@wxSmallPush', $data);
    }


}